angular.module('app.services', [
    'ngResource'
]).value('version', '0.1').factory('logger', function (toastr, $window) {
    toastr.options.timeOut = 7500;
    toastr.options.positionClass = 'toast-bottom-right';
    var logger = {
        error: error,
        info: info,
        success: success,
        warning: warning,
        log: log
    };
    function error(message, title) {
        toastr.error(message, title);
        console.log("Error: " + message);
    }
    ;
    function info(message, title) {
        toastr.info(message, title);
        console.log("Info: " + message);
    }
    ;
    function success(message, title) {
        toastr.success(message, title);
        console.log("Success: " + message);
    }
    ;
    function warning(message, title) {
        toastr.warning(message, title);
        console.log("Warning: " + message);
    }
    ;
    function log() {
        var console = $window.console;
        !!console && console.log && console.log.apply && console.log.apply(console, arguments);
    }
    return logger;
}).factory('AdminServices', function ($resource) {
    var AdminServices = $resource('/api/:controller/:id', [], {
        GetByDesc: {
            method: 'GET',
            params: {
                controller: 'admin'
            },
            isArray: true
        },
        Get: {
            method: 'GET',
            params: {
                controller: 'admin'
            }
        },
        Post: {
            method: 'POST',
            params: {
                controller: 'admin'
            }
        },
        Put: {
            method: 'PUT',
            params: {
                controller: 'admin',
                id: '@id'
            }
        },
        Delete: {
            method: 'DELETE',
            params: {
                controller: 'admin',
                id: '@id'
            }
        }
    });
    return AdminServices;
}).factory('TeamServices', function ($resource) {
    var TeamServices = $resource('/api/:controller/:id', [], {
        GetTeams: {
            method: 'GET',
            params: {
                controller: 'team'
            },
            isArray: true
        },
        GetTeam: {
            method: 'GET',
            params: {
                controller: 'teamDetail'
            }
        },
        AddTeam: {
            method: 'POST',
            params: {
                controller: 'team'
            }
        },
        PostMember: {
            method: 'POST',
            params: {
                controller: 'teamDetail'
            }
        },
        PutTeam: {
            method: 'PUT',
            params: {
                controller: 'teamDetail',
                id: '@id'
            }
        },
        DeleteTeam: {
            method: 'DELETE',
            params: {
                controller: 'team',
                id: '@id'
            }
        },
        DeleteTeamMember: {
            method: 'DELETE',
            params: {
                controller: 'teamDetail',
                id: '@id'
            }
        }
    });
    return TeamServices;
}).factory('TeamMemberStateService', function () {
    var Member;
    var getMember = function () {
        return Member;
    };
    var setMember = function (m) {
        Member = m;
    };
    return {
        getMember: getMember,
        setMember: setMember
    };
}).factory('IncidentServices', function ($resource) {
    var IncidentServices = $resource('/api/:controller/:id', [], {
        GetIncidents: {
            method: 'GET',
            params: {
                controller: 'incident'
            },
            isArray: true
        },
        GetIncident: {
            method: 'GET',
            params: {
                controller: 'incidentDetail'
            }
        },
        GetLocation: {
            method: 'GET',
            params: {
                controller: 'locationDetail'
            }
        },
        PostIncident: {
            method: 'POST',
            params: {
                controller: 'incidentDetail'
            }
        },
        PutIncident: {
            method: 'PUT',
            params: {
                controller: 'incidentDetail',
                id: '@id'
            }
        },
        DeleteIncident: {
            method: 'DELETE',
            params: {
                controller: 'incidentDetail',
                id: '@id'
            }
        }
    });
    return IncidentServices;
}).factory('LocationServices', function ($resource) {
    var LocationServices = $resource('/api/:controller/:id', [], {
        GetLocation: {
            method: 'GET',
            params: {
                controller: 'locationDetail',
                id: '@id'
            }
        },
        GetNewLocation: {
            method: 'GET',
            params: {
                controller: 'locationDetail',
                incidentId: '@incidentId'
            }
        },
        GetLatLong: {
            method: 'GET',
            params: {
                controller: 'locationDetail',
                address: '@address'
            },
            isArray: true
        },
        PostLocation: {
            method: 'POST',
            params: {
                controller: 'locationDetail'
            }
        },
        PutLocation: {
            method: 'PUT',
            params: {
                controller: 'locationDetail',
                id: '@id'
            }
        },
        DeleteLocation: {
            method: 'DELETE',
            params: {
                controller: 'locationDetail',
                id: '@id'
            }
        }
    });
    return LocationServices;
}).factory('VictimsServices', function ($resource) {
    var VictimsServices = $resource('/api/:controller/:id', [], {
        GetVictims: {
            method: 'GET',
            params: {
                controller: 'victims',
                id: '@id'
            },
            isArray: true
        },
        PostVictim: {
            method: 'POST',
            params: {
                controller: 'victims'
            }
        },
        PutVictim: {
            method: 'PUT',
            params: {
                controller: 'victims',
                id: '@id'
            }
        },
        DeleteVictim: {
            method: 'DELETE',
            params: {
                controller: 'victims',
                id: '@id'
            }
        }
    });
    return VictimsServices;
}).factory('Users', function ($http) {
    return {
        getAll: function (success, error) {
            $http.get('/users').success(success).error(error);
        }
    };
});
